<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class OrderCheck extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'order';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'paytime_text',
        'sendtime_text',
        'receipttime_text',
        'completetime_text',
        'canceltime_text',
        'mode_text',
        'status_text',
        'is_checking_text',
        'is_diagnose_text',
        'checking_status_text',
        'samplingtime_text',
        'detectiontime_text',
        'reporttime_text',
        'senddetectiontime_text'
    ];



    public function getModeList()
    {
        return ['1' => __('Mode 1'), '2' => __('Mode 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '6' => __('Status 6'), '7' => __('Status 7')];
    }

    public function getIsCheckingList()
    {
        return ['1' => __('Is_checking 1'), '2' => __('Is_checking 2')];
    }

    public function getIsDiagnoseList()
    {
        return ['1' => __('Is_diagnose 1'), '2' => __('Is_diagnose 2')];
    }

    public function getCheckingStatusList()
    {
        return ['1' => __('Checking_status 1'), '2' => __('Checking_status 2'), '3' => __('Checking_status 3'), '4' => __('Checking_status 4'), '5' => __('Checking_status 5')];
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getSendtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sendtime']) ? $data['sendtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReceipttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['receipttime']) ? $data['receipttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCompletetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['completetime']) ? $data['completetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCanceltimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['canceltime']) ? $data['canceltime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getModeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['mode']) ? $data['mode'] : '');
        $list = $this->getModeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsCheckingTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_checking']) ? $data['is_checking'] : '');
        $list = $this->getIsCheckingList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsDiagnoseTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_diagnose']) ? $data['is_diagnose'] : '');
        $list = $this->getIsDiagnoseList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCheckingStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['checking_status']) ? $data['checking_status'] : '');
        $list = $this->getCheckingStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSamplingtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['samplingtime']) ? $data['samplingtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getDetectiontimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['detectiontime']) ? $data['detectiontime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReporttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['reporttime']) ? $data['reporttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getSenddetectiontimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['senddetectiontime']) ? $data['senddetectiontime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setSendtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setReceipttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCompletetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCanceltimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setSamplingtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDetectiontimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setReporttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setSenddetectiontimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function doctors()
    {
        return $this->belongsTo('Doctors', 'doctors_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function shopapply()
    {
        return $this->hasOne('ShopApply', 'admin_id', 'sell_id', [], 'LEFT')->setEagerlyType(0);
    }
}
